import { getReqCategoryList,getMockBanner,getMockFloor} from '@/api';

const state={
    categoryList:[],
    bannerList:[],//轮播图数据
    floorList:[]//楼层数据
};
const mutations={
    RECEIVE_CATEGORYLIST(state,categoryList){
        state.categoryList=categoryList
    },
    RECEIVE_BANNERLIST(state,bannerList){
        state.bannerList=bannerList
    },
    //获取楼层
    RECEIVE_FLOORLIST(state,floorList){
        state.floorList=floorList
    }
};
const actions={
   async getCategoryList({commit}){
    try {
        const result=await getReqCategoryList();
        commit('RECEIVE_CATEGORYLIST',result.data)
        
    } catch (error) {
        alert('获取失败')
        
    }

    },
    //获取轮播图数据
   async getBannerList({commit}){
       try {
        const result= await getMockBanner();
        if(result&&result.code===200){
            commit('RECEIVE_BANNERLIST',result.data)
        }
       } catch (error) {
        console.log(error);
       }
    },
    //获取楼层数据
    async getFloorList({commit}){
        const result= await getMockFloor();
        if(result&&result.code===200){
            commit('RECEIVE_FLOORLIST',result.data)
        }
    }

    
};
const getters={};
export default {
    state,
    mutations,
    actions,
    getters
}